package cn.zzt.carsRental.common.util;


/**
 * 分页工具类
 * @author ZZT
 *
 */
public class PageInfoUtil
{
	/* 总条数 */
	private int totalRecord;
	/* 每页条目数 */
	private int pageSize;
	
	/* 当前页 */
	private int currentPage;
	/* 总页数 */
	private int totalPage;
	
	/* 上一页 */
	private int prePage;
	/* 下一页 */
	private int nextPage;
	
	/* 当前页的起始条数 */
	private int currentRecordStart;
	
	
	public int getTotalRecord()
	{
		return totalRecord;
	}
	public void setTotalRecord(int totalRecord)
	{
		this.totalRecord = totalRecord;
	}
	public int getPageSize()
	{
		return pageSize;
	}
	public void setPageSize(int pageSize)
	{
		this.pageSize = pageSize;
	}
	public int getCurrentPage()
	{
		/* 判断当前页是否小于第一页，如果小于，则令其等于第一页 */
		if (this.currentPage <1)
		{
			this.currentPage = 1;
		}
		/* 判断当前页是否大于总页数，如果大于，令其等于总页数 */
		if (this.getTotalRecord() >0 && this.currentPage>this.getTotalPage())
		{
			this.currentPage = this.getTotalPage();
		}
		return currentPage;
	}
	public void setCurrentPage(int currentPage)
	{
		this.currentPage = currentPage;
	}
	public int getTotalPage()
	{
		this.totalPage = (int) Math.ceil((1.0 * this.getTotalRecord())/this.getPageSize());
		return totalPage;
	}
	public int getPrePage()
	{
		this.prePage = this.currentPage - 1;
		if (this.prePage < 1)
		{
			this.prePage = 1;
		}
		return prePage;
	}
	public int getNextPage()
	{
		this.nextPage = this.getCurrentPage() + 1;
		if (this.getTotalRecord()>0 && this.nextPage > this.getTotalPage())
		{
			this.nextPage = this.getTotalPage();
		}
		return nextPage;
	}
	public int getCurrentRecordStart()
	{
		this.currentRecordStart = (this.getCurrentPage() - 1)*this.getPageSize();
		return currentRecordStart;
	}
	
	@Override
	public String toString()
	{
		return "pageInfoUtil [totalRecord=" + this.getTotalRecord() + ", pageSize=" + this.getPageSize() + ", currentPage=" + this.getCurrentPage()
				+ ", totalPage=" + this.getTotalPage() + ", prePage=" + this.getPrePage() + ", nextPage=" + this.getNextPage()
				+ ", currentRecordStart=" + this.getCurrentRecordStart() + "]";
	}
	
	public static void main(String[] args)
	{
		PageInfoUtil pageInfoUtil = new PageInfoUtil();
		pageInfoUtil.setTotalRecord(55);
		pageInfoUtil.setCurrentPage(3);
		pageInfoUtil.setPageSize(10);
		System.out.println(pageInfoUtil);
	}
	
}